import { Faker, zh_CN } from "@faker-js/faker";
import { open } from "node:fs/promises";

const faker = new Faker({
	locale: [zh_CN],
});

let id = 0;

export function createRandomData() {
	return {
		type: faker.datatype.boolean() ? "pay" : "inconme",
		money: faker.number.int({ min: -10000, max: 10000 }),
		data: faker.date.anytime(),
		// useFor: faker,
		id: id++,
	};
}

const ka = faker.helpers.multiple(createRandomData, {
	count: 20,
});

open("./server/data.json", "w+").then((filehandler) => {
	filehandler.write(JSON.stringify({ ka }));
	filehandler.close();
});
